package com.Ivy.thread.object;
//消费者负责消费产品
public class Consumer extends Thread {
    private Warehouse warehouse;
    private boolean stopping;

    public Warehouse getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    public boolean isStopping() {
        return stopping;
    }

    public void setStopping(boolean stopping) {
        this.stopping = stopping;
    }

    public Consumer(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    //方法：消费
    public void purchase() throws InterruptedException {
        this.warehouse.doPurchase();
    }
    //重写Thread类的run方法
    @Override
    public void run(){
        while (true){
            try {
                this.purchase();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (stopping){
                break;
            }
        }

    }

}
